﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace quizzer_linq_3
{
    /**Class: Board Question
     * @author Spencer Estes
     * @version 1.0
     * Course : ITEC 4860 Spring 2012
     * Written: April , 2012
     * 
     * This class holds question information drawn from the Quizzer_Data_Access and is used
     * to populate the QuestionPopup.
     * 
     * Purpose: Hold question information from the Database
    */
    public class BoardQuestion
    {
        //Database object
        public Quizzer_Data_Access dataAccess = new Quizzer_Data_Access();

        //The ID of the question pulled from the database
        public string questionID;

        //The subcategory of the question
        public string subCategory;

        //The topic of the question
        public string topic;

        //The content of the question. The actual question to be asked
        public string content;

        //The difficulty of the question
        public string difficulty;

        //The correct answer of the question
        public string correctAnswer;

        //An array of the wrong answers
        public string[] wrongAnswers;


        public BoardQuestion()
        {
            //This should never get called -SE
        }

        /** Method: BoardQuestion
         * @author: Spencer Estes
         * Populates the public fields so this object can be accessed.
         * 
         * @param questionID the ID number of the question in string form
         * 
        */
        public BoardQuestion(string questionID)
        {
            int questionIDInt = Convert.ToInt32(questionID);
            String questionInfo = dataAccess.GetQuestion(questionIDInt);
            string[] splitQuestion = questionInfo.Split('|');
            if (splitQuestion[0] != "")
            {
                //Console.WriteLine("questionInfo is: " + questionInfo);

                //
                //0 = QuestionID, 1 = SubCategoryID, 2 = Topic, 3 = TheQuestion, 4 = DifficultyLevel, 
                //5 = PublicAccess, 6 = Ans01, 7 = Ans02, 8 = Ans03, 9 = Ans04, 10 = Ans05, 
                //11 = Rating, 12 = Feedback, 13 = ProfessorID
                questionID = splitQuestion[0];
                subCategory = splitQuestion[1];
                topic = splitQuestion[2];
                content = splitQuestion[3];
                difficulty = splitQuestion[4];
                correctAnswer = splitQuestion[6];
                wrongAnswers = new string[4];
                for (int wrongAnswerCounter = 0; wrongAnswerCounter < wrongAnswers.Length; wrongAnswerCounter++)
                {
                    //offsetCounter represents the index of the wrong answers. The first wrong answer starts at
                    //index 7 and ends at index 10
                    int offsetCounter = 7 + wrongAnswerCounter;
                    wrongAnswers[wrongAnswerCounter] = splitQuestion[offsetCounter];
                }
            }
        }
    }
}
